<template>
  <div>
    <div
      class="wrapper-container"
      style="display: flex; flex-direction: column; width: 100%"
    >
      <div class="search-container">
        <div class="search-container-left" style="display: flex;align-items: center;">
          <div
            class="search-container-item"
            v-for="(select, index) in selectList"
            :key="index"
          >
            <div v-if="select.type === 'select'" class="box">
              <span v-show="select.name">{{ select.name }}</span>

              <el-select
                v-model="select.val"
                style="width: 90px"
                size="mini"
                placeholder="请选择"
                clearable
              >
                <el-option
                  v-for="item in select.valList"
                  :key="item.id"
                  :label="item.name"
                  :value="item.id"
                >
                </el-option>
              </el-select>
            </div>
            <div class="box" v-if="select.type === 'date'" style="width: 350px">
              <span class="demonstration" v-show="select.name">{{
                select.name
              }}</span>
              <el-date-picker
              style="width:120px"
              value-format="yyyy-MM-dd"
                v-model="select.val1"
                type="date"
                placeholder="选择日期"
                prefix-icon="aaa"
              >
              </el-date-picker>
              --
              <el-date-picker
              style="width:120px"
              value-format="yyyy-MM-dd"
                v-model="select.val2"
                type="date"
                placeholder="选择日期"
                prefix-icon="aaa"
              >
              </el-date-picker>
            </div>
            <div v-if="select.type === 'MultiSelect'" class="box"></div>
            <div v-if="select.type === 'btn'" class="box">
              <span class="demonstration" v-show="select.name">{{
                select.name
              }}</span>
              <el-input
                v-model="select.val"
                placeholder="请输入内容"
              ></el-input>
            </div>
          </div>
          <div class="search-button" style="margin-left: 150px" @click="queryDAteClass">
            <img src="../../../../assets/assessment/icon-search.png" alt="" />
            <span>查询</span>
          </div>
          <div class="search-button" style="margin-left:20px" @click="resetAll">
            <!-- <img src="../../../../assets/assessment/icon-search.png" alt="" /> -->
            <span>重置</span>
          </div>
        </div>
      </div>
    </div>

    <div class="title-center">
      <div>{{startDate}} 至 {{endDate}}</div>
    </div>

    <div class="export-top" @click="exportData()" style="float: right;
    margin-top: -40px;
    margin-right: 20px;">
      <img src="../../../../assets/assessment/icon-export.png" alt="" />
      <span>&ensp;导出Excel</span>
    </div>

    <div class="assessment-container">
      <div class="table-container">
        <el-table
          :data="tableData"
          border
          class="table-data"
          row-class-name="row-class"
          cell-class-name="cell-class"
          header-row-class-name="header-row-class"
          header-cell-class-name="header-cell-class"
          style="height: calc(100vh - 370px); overflow-y: auto"
        >
          <el-table-column prop="coursedate" label="上课日期" align="center">
          </el-table-column>
          <el-table-column prop="courseJc" label="上课节次" align="center">
          </el-table-column>
          <el-table-column prop="courseName" label="课程名称" align="center">
          </el-table-column>
          <el-table-column prop="jxbMcList" label="教学班" align="center">
            <template slot-scope="scoped">
              <span v-for="item in scoped.row['jxbMcList']">{{item}}、</span>
            </template>
          </el-table-column>
          <el-table-column
            prop="zybcList"
            width="450px"
            label="上课专业班次"
            align="center"
          >
          <template slot-scope="scoped" >
            <div v-if="scoped.row['zybcList'] != null && scoped.row['zybcList'] != undefined">
              <span v-for="item in scoped.row['zybcList']">{{item.name}}({{item.rs}}人)、</span>
            </div>
            </template>
          </el-table-column>
          <el-table-column
            prop="courseplace"
            label="上课场地"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="teachtask"
            label="主讲教员"
            align="center"
          >
          </el-table-column>
          <el-table-column
            prop="assistant"
            label="助教"
            align="center"
          >
          </el-table-column>
        </el-table>
      </div>
    </div>
    <div class="wrapper-container">
      <div class="bottom-block" style="display: block">
        <div class="text">当前共找到{{ total }}条记录,当前显示{{ startPage }}-{{ endPage }}条</div>
      </div>
      <div class="pagination-block">
        <el-pagination
          prev-text="上一页"
          next-text="下一页"
          :page-size="pageSize"
          layout="prev, pager, next, jumper"
          :total="total"
          @current-change="handleCurrentChange"
          :current-page="currentPage"
        >
        </el-pagination>
      </div>
    </div>

  </div>
</template>

<script>
import {kscx_kcb_sjd, queryCommonXueqi, kscx_kcb_exportSjd, queryDefaultXueQi} from "@/api/trainingManagement/place.js";
import tablelist from "@/views/comonents/tablelist";
import ButtonItem from "@/components/ButtonItem.vue";

export default {
  components: {
    tablelist,
    ButtonItem,
  },
  data() {
    return {
      total: 0, //总条数
      pageSize: 50, //条数
      startPage: 0, //开始条数
      endPage: 0, //结束条数
      currentPage: 1, //当前页数
      jsonFields: {
        上课日期: "coursedate",
        上课节次: "courseJc",
        课程名称: "courseName",
        教学班: "jxbMcList",
        上课专业班次: "zybcList",
        上课场地: "courseplace",
        主讲教员: "teachtask",
        助教: "assistant"
      },
      startDate: "",// 开始时间
      endDate: "", //结束时间
      selectList: [
        {
          type: "select",
          name: "学期:",
          val: "",
          valList: [],
        },
        {
          type: "date",
          name: "上课时间",
          val1: "",
          val2: "",
        },
      ],
      tableData: [],
    };
  },
  created() {},
  mounted() {
    this.getDefaultXueQi();
    this.queryCommonXueqi();
    // this.queryDAteClass()
  },
  methods: {
    async getDefaultXueQi(){
      queryDefaultXueQi().then(res=>{
        if(res.data.code == 200){
          this.selectList[0].val = res.data.data;
          // this.semester = res.data.data;
        }
      }).then(()=>{
        // this.queryDAteClass()
      })
    },
    exportData() {
      if (this.selectList[1].val1 == "" || this.selectList[1].val1 == null) {
        this.$message.warning("请先选择开始日期!");
        return
      }
      if (this.selectList[1].val2 == "" || this.selectList[1].val2 == null) {
        this.$message.warning("请先选择结束日期!");
        return
      }
      this.startDate = this.selectList[1].val1;
      this.endDate = this.selectList[1].val2;
      var data = {
        "xueqi": this.selectList[0].val,
        "startTime": this.selectList[1].val1,
        "endTime": this.selectList[1].val2,
      }
      kscx_kcb_exportSjd(data).then((res) => {
        /** 获取生成设置好的文件名 */
        // var filename = res.headers["content-disposition"];
        // filename = filename.split("=")[1];
        // // 我看好多博客此处没有再次编码，我这里不重新编码，文件名称总是乱码
        // filename = escape(filename);
        // filename = decodeURIComponent(filename, "utf-8");
        // console.log(filename);
        // console.log(res.data);
        /** 接收文件流 */
        const blob = new Blob([res.data]);
        let url = URL.createObjectURL(blob);
        /** 模拟浏览器操作Document，并模拟下载动作 */
        let link = document.createElement("a");
        link.style.display = "none";
        link.href = url;
        link.setAttribute("download", "课表.xlsx");
        document.body.appendChild(link);
        link.click();
      });
    },
    // 查询时间段列表数据
    async queryDAteClass() {
      if (this.selectList[1].val1 == "" || this.selectList[1].val1 == null) {
        this.$message.warning("请先选择开始日期!");
        return
      }
      if (this.selectList[1].val2 == "" || this.selectList[1].val2 == null) {
        this.$message.warning("请先选择结束日期!");
        return
      }
      this.startDate = this.selectList[1].val1;
      this.endDate = this.selectList[1].val2;
      var data = {
        "xueqi": this.selectList[0].val,
        "startTime": this.selectList[1].val1,
        "endTime": this.selectList[1].val2,
      }
      const res = await kscx_kcb_sjd(data, this.currentPage, this.pageSize);
      if (res.data.code == 200) {
        var ttdata = res.data.data.records;
        ttdata.forEach(item => {
          item.coursedate = item.coursedate.substring(0,10);
        });
        this.tableData = ttdata;
        this.total = res.data.data.total;
        var length = this.tableData.length;
        this.calculatePage(
          this.pageSize,
          res.data.data.current, length);
      }
    },
    //重置
    resetAll(){
      this.selectList[0].val = '';
      this.selectList[1].val1 = '';
      this.selectList[1].val2 = '';
      this.startDate = '';
      this.endDate = '';
    },
    // 计算开始和结束条数
    calculatePage(pageSize, current, length) {
      if (current == 1) {
        if (length != 0) {
          this.startPage = 1;
          this.endPage = length;
        }
      } else {
        this.startPage = pageSize * (current - 1) + 1;
        this.endPage = parseInt(this.startPage)  + parseInt(length) - 1;
      }
    },
    handleCurrentChange(val) {
      this.currentPage = val;
      this.queryDAteClass();
    },
    // 获取学期列表
    async queryCommonXueqi() {
      const res = await queryCommonXueqi();
      if (res.data.code == 200) {
        this.selectList[0].valList = res.data.data;
        // this.selectList[0].val = this.selectList[0].valList[0].id;
      }
    },
  },
  computed: {}, //计算属性
};
</script>
<style lang="less" scoped>
.choose-ypr-container {
  width: 767px;
  margin: 0px auto;
  .choose-ypr-search-container {
    .el-input--prefix .el-input__inner {
      padding-left: 30px;
    }
    .el-input__inner {
      &::placeholder {
        color: #b8b8b8;
      }
      &::-webkit-input-placeholder {
        /* WebKit browsers 适配谷歌 */
        color: #b8b8b8;
      }
      &:-moz-placeholder {
        /* Mozilla Firefox 4 to 18 适配火狐 */
        color: #b8b8b8;
      }
      &::-moz-placeholder {
        /* Mozilla Firefox 19+ 适配火狐 */
        color: #b8b8b8;
      }
      &:-ms-input-placeholder {
        /* Internet Explorer 10+  适配ie*/
        color: #b8b8b8;
      }
    }
    display: flex;
    flex-direction: row;
    align-items: center;
    .title {
      font-size: 18px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
      margin-right: 5px;
    }

    .button-list {
      display: flex;
      flex-direction: row;
      align-items: center;
      margin-left: 21px;
      .button-item {
        display: flex;
        flex-direction: row;
        align-items: center;
        justify-content: center;
        position: relative;
        width: 69px;
        height: 27px;
        line-height: 27px;
        border: 1px solid #004ca7;
        border-radius: 4px;
        margin-right: 10px;
        text-align: center;
        font-size: 14px;
        font-family: Microsoft YaHei;
        font-weight: 400;
        color: #004ca7;
        .del-icon {
          position: absolute;
          right: 0px;
          top: 0px;
          width: 12px;
          height: 12px;
          padding: 2px;
        }
      }
    }
  }
  .choose-ypr-table-container {
    margin-top: 30px;
    .el-table td,
    .el-table th.is-leaf,
    .el-table--border,
    .el-table--group {
      border-color: #c7d7eb;
    }
    .el-table__header tr,
    .el-table__header th {
      padding: 0;
      height: 57px;
      background-color: #edf2f9;
      font-size: 16px;
      font-family: Microsoft YaHei;
      font-weight: bold;
      line-height: 20px;
      color: #004ca7;
    }
    .el-table__body tr,
    .el-table__body td {
      padding: 0;
      height: 51px;
    }
    .table-data {
      width: 100%;
      border: 0.8px solid #004ca7;
      /*border-radius: 9px;*/
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #004ca7;
    }
  }
}
.assessment-container {
  .el-dialog__body {
    height: 251px;
  }
  .el-dialog__footer {
    padding: 10px 20px 45px;
  }
  .el-checkbox__inner:hover {
    border-color: #004ca7;
  }
  .el-checkbox__inner {
    border: 1px solid #004ca7;
    border-radius: 0;
    height: 18px;
    width: 18px;
  }
  .el-checkbox__inner::after {
    height: 10px;
    left: 6px;
  }
  .el-checkbox__input.is-checked .el-checkbox__inner,
  .el-checkbox__input.is-indeterminate .el-checkbox__inner {
    background-color: #004ca7;
    border-color: #004ca7;
  }
  .el-checkbox__input.is-checked + .el-checkbox__label {
    color: #004ca7;
  }
  .el-checkbox.is-bordered.is-checked {
    border-color: #004ca7;
  }
  .el-checkbox__input.is-focus .el-checkbox__inner {
    border-color: #004ca7;
  }
}
</style>
<style lang="less" scoped>
@import "../../../../styles/text.less";
.assessment-container .table-container {
  // overflow: scroll;
}
.assessment-container .table-container .table-header {
  width: 1935px;
}
.assessment-container .table-container .table-body {
  width: 1935px;
}
/deep/ .szjky .el-dialog__body {
  height: 432px;
}
.pagination-block {
  margin-top: 20px;
  display: flex;
  flex-direction: row;
  justify-content: center;
}
</style>
<style lang="less" scoped>
@import "../../../../styles/supervision.less";

.wrapper-container {
  width: calc(100% - 20px);
  margin: 0 auto;
}

/deep/ .table-container {
  .el-table td,
  .el-table th.is-leaf,
  .el-table--border,
  .el-table--group {
    border-color: #c7d7eb;
  }

  .el-table__header tr,
  .el-table__header th {
    padding: 0;
    height: 76px;
    background-color: #edf2f9;
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: bold;
    line-height: 20px;
    color: #004ca7;
  }

  .el-table__body tr,
  .el-table__body td {
    padding: 0;
    height: 86px;
  }

  .wrapper-button {
    display: flex;
    flex-direction: column;
    align-items: center;

    > div {
      margin-bottom: 8px;
    }
  }
  .table-data {
    width: 100%;
    border: 0.8px solid #004ca7;
    /*border-radius: 9px;*/
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #004ca7;
  }
}

.wrapper-container .search-container .search-container-left {
  width: 100%;
  flex-wrap: wrap;
  .search-container-item {
    width: 12%;
    margin-right: 0px;
    .box {
      > span {
        text-align: left;
      }
      display: flex;
      justify-content: space-evenly;
      // margin-bottom: 20px;
      align-items: center;
      /deep/ .el-input__inner {
        height: 28px;
      }
    }
  }
}

/deep/.el-date-editor.el-input {
  width: 110px;
}
/deep/ .el-input--medium {
  width: 110px;
  .el-input__inner {
    height: 28px;
    width: 110px;
    padding: 0px 18px;
  }
}
/deep/ .el-table thead {
  color: #004ca7 !important;
}

.btn {
  margin-top: 271px;
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 271px;
  .submit {
    width: 84px;
    height: 27px;
    line-height: 8px;
  }
}
.bottom-block {
  // display: flex;
  flex-direction: row;
  justify-content: space-between !important;
  .export-button {
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    flex-direction: row;
    align-items: center;
    justify-content: center;
    margin-top: 14px;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      margin-left: 12px;
      font-size: 14px;
      font-family: Microsoft YaHei;
      font-weight: 400;
      color: #f3b815;
    }
  }
  .text {
    font-size: 14px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    line-height: 39px;
    color: #004ca7;
  }
}

.search-button {
  width: 77px;
  height: 28px;
  line-height: 28px;
  background: #f1f8fe;
  border: 1px solid #51aef6;
  border-radius: 6px;
  cursor: pointer;
  display: flex;
  flex-direction: row;
  align-items: center;
  justify-content: center;
  > span {
    font-size: 16px;
    font-family: Microsoft YaHei;
    font-weight: 400;
    color: #51aef6;
  }
  > img {
    width: 20px;
    height: 20px;
    margin-right: 4px;
  }
}

.mar-lef-2 {
  margin-left: 20px;
}
.undeLine {
  text-decoration: underline;
  cursor: pointer;
}

.edit-icon {
  font-size: 20px;
  color: #02c86c;
  margin-left: 10px;
  cursor: pointer;
}

.body-manual-container {
  > div:nth-child(1) {
    width: 1200px;
    // height: 785px;
    border: 1px solid rgba(0, 76, 167, 0.8);
    border-radius: 6px;
    margin: 30px auto 0;
    ul {
      list-style: none;
      li {
        border-bottom: 1px solid rgba(0, 76, 167, 0.4);
        height: auto;
        > span {
          box-sizing: border-box;
          display: inline-block;
          font-size: 14px;
          color: rgba(0, 76, 167, 1);
          padding-left: 54px;
          border-right: 1px solid rgba(0, 76, 167, 0.4);
          height: 60px;
          padding-top: 20px;
          vertical-align: middle;
          &:nth-child(n) {
            // width: 357px;
            width: 290px;
          }
          // &:nth-child(2n) {
          // 	width: 444px;
          // }
          &:last-child {
            border-right: none;
          }
          &.active {
            font-size: 16px;
            color: rgba(0, 76, 167, 1);
            font-weight: bold;
            background: rgba(77, 129, 192, 0.1);
            text-align: center;
            padding-left: 0;
          }
          > span {
            color: rgba(255, 56, 25, 1);
          }
          > div {
            width: 100%;
          }
        }
      }
    }
  }
}

.add-icon {
  font-size: 28px;
  color: #f3b815;
  margin-left: 10px;
  cursor: pointer;
}

.date-select {
  height: 100%;
  padding: 0;
  padding-left: 40px;
  overflow-y: auto;
  width: 900px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.date-select-show {
  height: 100%;
  width: 500px;
  display: flex;
  align-items: center;
  flex-direction: row;
  flex-wrap: wrap;
}

.class-tip {
  color: #004ca7;
  font-size: 16px;
  font-weight: bold;
  text-align: center;
  margin: 40px;
}

.tip-text {
  color: #004ca7;
  margin-left: 5px;
  font-size: 16px;
}

/deep/ .xzjy .el-dialog__body {
  padding: 0 !important;
  .wrapper-container {
    width: 100% !important;
  }
  .wrapper-container .search-container .search-container-left {
    margin-left: 20px;
    flex-wrap: wrap;
    .search-container-item {
      width: 200px;
      margin-right: 10px;
      .box {
        > span {
          text-align: left;
          width: 80px;
        }
        display: flex;
        justify-content: space-evenly;
        margin-bottom: 20px;
        align-items: center;
        .el-input--medium .el-input__inner {
          height: 28px;
        }
      }
    }
  }
}

/deep/ .el-tree-node__expand-icon.expanded {
  color: rgb(0, 76, 167);
}

.xzjy .tree {
  padding: 30px;
  color: rgb(0, 76, 167);
  font-weight: bold;
  font-size: 16px;
}

.export-right {
  display: flex;
  align-items: center;
  justify-content: end;
  margin-right: 70px;
  margin-top: -40px;
  margin-bottom: 20px;
}

.title-center {
  margin: 15px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: bold;
  color: #004ca7;
}

.assessment-container {
  width: calc(100% - 20px);
  .table-container {
     width: 100%;
  }
}

.export-top {
      cursor: pointer;
    width: 127px;
    height: 27px;
    background: #fff6ef;
    border: 1px solid #f3b815;
    border-radius: 4px;
    display: flex;
    -webkit-box-orient: horizontal;
    -webkit-box-direction: normal;
    flex-direction: row;
    -webkit-box-align: center;
    align-items: center;
    -webkit-box-pack: center;
    justify-content: center;
    > img {
      width: 17px;
      height: 17px;
    }
    > span {
      color: #f3b815;
    }
}
</style>
